<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class School_course extends MY_Controller {
	function __construct(){
		parent::__construct();
		$this->load->model('Courses');
	}

	function index($school_id = 0, $course_type = 0, $limit = 0){
		$school_id = 0;
		$post_data = $this->input->post();
		if($post_data){
			$school_id = !empty($post_data['school_id']) ? $post_data['school_id'] : 0;
			$course_type = !empty($post_data['course_type']) ? $post_data['course_type'] : 0;
		}

		//获取课程
		$course_list = $this->Courses->get_course_all($limit,$this->offset,$school_id,$course_type);
		$this->smarty->assign("course_list", $course_list['result']);

		$this->load->library('pagination');
		$page_config['base_url'] = '/school_course/index/'.$school_id.'/'.$course_type;
		$page_config['total_rows'] = $course_list['total_count'];
		$page_config['per_page'] = $this->offset;
		$page_config['uri_segment'] = 5;
		$this->pagination->initialize($page_config);
		$pagination = $this->pagination->create_links();

		$this->smarty->assign("pagination", $pagination);
		
		//获取网校
		$this->load->model('Schools');
		$schools = $this->Schools->get_school_all();
		$this->smarty->assign("schools", $schools);
		

		$this->smarty->assign("school_id", $school_id);
		$this->smarty->assign("course_type", $course_type);
		$this->smarty->assign("current_url", "/school_course");
		$this->smarty->assign("action", "网校课程列表");
		$this->smarty->assign("menu", "course");
		$this->smarty->assign("type", 11);
        $school_info['id'] = $school_id;
        $this->smarty->assign("school_info", $school_info);
		$this->smarty->display("school/course_list.html");
	}

	function delete($id){
		$id = (array) $id;
		delete_data($id, "course");
		if($this->db->affected_rows() > 0){
			show_message($_SERVER['HTTP_REFERER'], "删除成功");
		}else{
			show_message($_SERVER['HTTP_REFERER'], "删除失败，请重试！");
		}
	}
}